number = int(input("Введите четырехзначное натуральное число: "))

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def largest_prime_from_digits(number):
    str_num = str(number)

    if len(str_num) != 4 or not str_num.isdigit():
        return 0

    max_prime = 0

    for i in range(len(str_num)):
        for j in range(i+1, len(str_num)+1):
            sub_num = int(str_num[i:j])
            if is_prime(sub_num):
                max_prime = max(max_prime, sub_num)

    return max_prime



print(largest_prime_from_digits(number))